<!--
搜索栏
props：
placeholder：默认的提示语
emit：
search：function(txt) 搜索的内容
-->
<template>
  <div class="container">
    <div class="input_div" :class="{isbtn:isbtn}">
      <i class="fa fa-search" aria-hidden="true"></i>
      <input type="text" :placeholder="placeholder" class="search_input" @focus="isbtn=true" v-model="search_txt" :class="{isbtn_input:isbtn}"
        @blur="isbtn=false">
    </div>
    <button class="search_button" v-bind:class="{show:isbtn}" @click="search()">搜索</button>
  </div>
</template>
<style lang="less" scoped>
@import url('./theme.less');
  /* placeholder样式 */
  .search_input::-webkit-input-placeholder {
    text-indent: 10px;
  }

  .search_input::-moz-input-placeholder {
    text-indent: 10px;
  }

  .search_input::-ms-input-placeholder {
    text-indent: 10px;
  }
  /* placeholder样式 */
  .container {
    width: 100%;
    height: @search-height;
    background: @search-background-color;
    float: left;
    i {
      float: left;
      width: 15px;
      margin-left: 5px;
      height: 15px;
      /* margin: 5px 5px; */
      margin-top: 7.5px;
    }
    .input_div {
      height: 30px;
      float: left;
      width: calc(100% - 20px);
      border-radius: 6px;
      background: @search-input-background;
      margin: 7px 10px;
      transition: width 0.5s;
      -moz-transition: width 0.5s;
      /* Firefox 4 */
      -webkit-transition: width 0.5s;
      /* Safari 和 Chrome */
      -o-transition: width 0.5s;
      &.isbtn {
        width: calc(100% - 70px);
      }
      .search_input {
        outline: none;
        width: calc(100%-20px);
        border: none;
        height: 30px;
        float: left;
        background: none;
        text-indent: 10px;
        transition: width 0.5s;
        -moz-transition: width 0.5s;
        /* Firefox 4 */
        -webkit-transition: width 0.5s;
        /* Safari 和 Chrome */
        -o-transition: width 0.5s;
        &.isbtn_input {
          width: calc(100% - 30px);
        }
      }

    }
    .search_button {
      width: 0px;
      height: 30px !important;
      margin-top: 7px;
      float: left;
      position: relative;
      left: -10px;
      white-space: nowrap;
      border: none;
      color: #454545 !important;
      opacity: 0;
      overflow: hidden;
      background: rgba(0, 0, 0, 0) !important;
      transition: all 0.5s;
      -moz-transition: all 0.5s;
      /* Firefox 4 */
      -webkit-transition: all 0.5s;
      /* Safari 和 Chrome */
      -o-transition: all 0.5s;
      visible: none;
      &.show {
        visibility: visible;
        width: 50px;
        opacity: 100;

      }
    }
  }
</style>
<script>
  export default {
    data: function () {
      return {
        isbtn: false,
        search_txt: ''
      }
    },
    props:{
        placeholder:{
            default: '请输入...'
        }
    },
    methods: {
      search: function () {
        this.$emit('search', this.search_txt);
      }
    }
  }

</script>
